package com.jhgsys.internal.incentive.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.incentive.entity.IncentiveQuotaAuditRecord;
import com.jhgsys.internal.incentive.service.IIncentiveQuotaAuditRecordService;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 *  Controller
 *
 * @author zhangwei
 * @date 2024-09-04 13:56:17
 */
@Slf4j
@Validated
@Controller
public class IncentiveQuotaAuditRecordController extends BaseController {

    @Autowired
    private IIncentiveQuotaAuditRecordService incentiveQuotaAuditRecordService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveQuotaAuditRecord")
    @RequiresPermissions("incentiveQuotaAuditRecord:view")
    public String incentiveQuotaAuditRecordIndex(){
        return FebsUtil.view("incentive/incentiveQuotaAuditRecord/incentiveQuotaAuditRecordList");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveQuotaAuditRecord/add")
    @RequiresPermissions("incentiveQuotaAuditRecord:add")
    public String incentiveQuotaAuditRecordAdd(){
        return FebsUtil.view("incentive/incentiveQuotaAuditRecord/incentiveQuotaAuditRecordEdit");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveQuotaAuditRecord/update/{id}")
    @RequiresPermissions("incentiveQuotaAuditRecord:edit")
    public String incentiveQuotaAuditRecordUpdate(Model model, @PathVariable("id") String id){
        model.addAttribute("incentiveQuotaAuditRecord", incentiveQuotaAuditRecordService.findIncentiveQuotaAuditRecordById(id));
        return FebsUtil.view("incentive/incentiveQuotaAuditRecord/incentiveQuotaAuditRecordEdit");
    }

    /**
     * 查询（所有）
     * @author zhangwei
     * @date 2024-09-04 13:56:17
     */
    @GetMapping("incentiveQuotaAuditRecord")
    @ResponseBody
    @RequiresPermissions("incentiveQuotaAuditRecord:view")
    public FebsResponse getAllIncentiveQuotaAuditRecords(IncentiveQuotaAuditRecord incentiveQuotaAuditRecord) {
        return new FebsResponse().success().data(incentiveQuotaAuditRecordService.findIncentiveQuotaAuditRecordList(incentiveQuotaAuditRecord));
    }

    /**
     * 查询（分页）
     * @author zhangwei
     * @date 2024-09-04 13:56:17
     */
    @GetMapping("incentiveQuotaAuditRecord/list")
    @ResponseBody
    @RequiresPermissions("incentiveQuotaAuditRecord:view")
    public FebsResponse incentiveQuotaAuditRecordList(QueryRequest request, IncentiveQuotaAuditRecord incentiveQuotaAuditRecord) {
        Map<String, Object> dataTable = getDataTable(this.incentiveQuotaAuditRecordService.findIncentiveQuotaAuditRecordPage(request, incentiveQuotaAuditRecord));
        return new FebsResponse().success().data(dataTable);
    }

    /**
     * 新增 IncentiveQuotaAuditRecord
     * @author zhangwei
     * @date 2024-09-04 13:56:17
     */
    @Log("新增IncentiveQuotaAuditRecord")
    @PostMapping("incentiveQuotaAuditRecord")
    @ResponseBody
    @RequiresPermissions("incentiveQuotaAuditRecord:add")
    public FebsResponse addIncentiveQuotaAuditRecord(@Valid IncentiveQuotaAuditRecord incentiveQuotaAuditRecord) throws FebsException {
        try {
            incentiveQuotaAuditRecord.setCreatedBy(getCurrentUser().getUserName());
            this.incentiveQuotaAuditRecordService.createIncentiveQuotaAuditRecord(incentiveQuotaAuditRecord);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "新增IncentiveQuotaAuditRecord失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 逻辑删除 IncentiveQuotaAuditRecord
     * @author zhangwei
     * @date 2024-09-04 13:56:17
     */
    @Log("逻辑删除IncentiveQuotaAuditRecord")
    @GetMapping("incentiveQuotaAuditRecord/delete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveQuotaAuditRecord:delete")
    public FebsResponse deleteIncentiveQuotaAuditRecord(@PathVariable("id") String incentiveQuotaAuditRecordIds) throws FebsException {
        try {
            IncentiveQuotaAuditRecord incentiveQuotaAuditRecord = new IncentiveQuotaAuditRecord();
            incentiveQuotaAuditRecord.setDeletedBy(getCurrentUser().getUserName());
            incentiveQuotaAuditRecord.setDeletedTime(new Date());
            incentiveQuotaAuditRecord.setDeletedFlg(FebsConstant.INVALID);
            this.incentiveQuotaAuditRecordService.deleteIncentiveQuotaAuditRecord(incentiveQuotaAuditRecord,incentiveQuotaAuditRecordIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveQuotaAuditRecord失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
    * 物理删除 IncentiveQuotaAuditRecord
    * @author zhangwei
    * @date 2024-09-04 13:56:17
    */
    @Log("物理删除IncentiveQuotaAuditRecord")
    @GetMapping("incentiveQuotaAuditRecord/physicallyDelete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveQuotaAuditRecord:delete")
    public FebsResponse physicallyDeleteIncentiveQuotaAuditRecord(@PathVariable("id") String incentiveQuotaAuditRecordIds) throws FebsException {
        try {
            this.incentiveQuotaAuditRecordService.physicallyDeleteIncentiveQuotaAuditRecord(incentiveQuotaAuditRecordIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveQuotaAuditRecord失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 修改 IncentiveQuotaAuditRecord
     * @author zhangwei
     * @date 2024-09-04 13:56:17
     */
    @Log("修改IncentiveQuotaAuditRecord")
    @PostMapping("incentiveQuotaAuditRecord/update")
    @ResponseBody
    @RequiresPermissions("incentiveQuotaAuditRecord:edit")
    public FebsResponse updateIncentiveQuotaAuditRecord(IncentiveQuotaAuditRecord incentiveQuotaAuditRecord) throws FebsException {
        try {
            incentiveQuotaAuditRecord.setUpdatedBy(getCurrentUser().getUserName());
            this.incentiveQuotaAuditRecordService.updateIncentiveQuotaAuditRecord(incentiveQuotaAuditRecord);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "修改IncentiveQuotaAuditRecord失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

}
